package com.hspedu.outputstream;

import java.io.*;

/**
 * @author DL5O
 * @version 1.0
 * 使用bufferedOutputStream 和bufferedInputStream
 * 使用他们可以完成二进制文件拷贝
 * 思考：字节流可以操作二进制文件，那么他可以操作文本文件嘛？可以的，字符本来就是字节
 */
public class BufferedCopy02 {
    public static void main(String[] args) throws IOException {
        String scrFilePath = "D:\\bg.png";//源文件位置
        String destFilePath = "D:\\ywl.png";//目标文件位置
        //BufferedInputStream继承了 FilterInputStream
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(scrFilePath));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(destFilePath));
        byte[] buf = new byte[50];
        int readLen = 0;
        //循环读取文件，并写入到目标文件中
        while((readLen = bufferedInputStream.read(buf)) != -1){
            bufferedOutputStream.write(buf,0,readLen);
        }

        //关闭流
        System.out.println("拷贝完毕...");
        bufferedInputStream.close();
        bufferedOutputStream.close();
    }
}
